﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static BaseHeightControl.Building;

namespace BaseHeightControl
{
    public partial class TakeOneBuilding : ObservableObject
    {
        [ObservableProperty]
        public Building _OneBuilding;

        public TakeOneBuilding()
        {
            Ini();
        }

        public delegate void ReBackDatas_InTake(string Msg = "");
        public event ReBackDatas_InTake? ReBackData_InTake;
        /// <summary>
        /// 初始化一个建筑物实例
        /// </summary>
        private void Ini()
        {
            OneBuilding = new Building();
            OneBuilding.ReBackData_InBuilding += OneBuilding_ReBackData_InBuilding;

            OneBuilding.Name = "和谐大厦B座";
            OneBuilding.Description = "辽宁省沈阳市铁西区，建设东路42号。这是和谐大厦B座，有两部电梯，地下1层，地上24层。";

            #region 安装电梯
            OneBuilding.AddBox(new BoxBody()
            {
                Name = "3号电梯",
                Description = "这是B座，有2个门，但只开一个。这是第一个电梯。",
                BoxHeight = 3.5m,
                BaseSensorHeight = 0.5m,
                CurrentHeight_FromSensor = 0.5m,
                TargetHeight_FromControl = 0.5m,//0.5m,
                IsDoorOpen = false,
                IsDevelopmentMode = false
            });
            OneBuilding.AddBox(new BoxBody()
            {
                Name = "4号电梯",
                Description = "这是B座，有2个门，但只开一个。这是第二个电梯。",
                BoxHeight = 3.5m,
                BaseSensorHeight = 0.5m,
                CurrentHeight_FromSensor = 0.5m,
                TargetHeight_FromControl = 0.5m,
                IsDoorOpen = false,
                IsDevelopmentMode = false
            });
            #endregion

            #region 配置楼层
            BaseHeightControl.Floor floor_B1 = new BaseHeightControl.Floor() { FloorNumber = -1, Height = 6.0d, IsUpButtonOn = false, IsDownButtonOn = false ,IsTopOrBottom=FloorLevel.Bottom};
            BaseHeightControl.Floor floor_1 = new BaseHeightControl.Floor() { FloorNumber = 1, Height = 6.0d, IsUpButtonOn = false, IsDownButtonOn = false, IsBaseFloor = true };
            BaseHeightControl.Floor floor_2 = new BaseHeightControl.Floor() { FloorNumber = 2, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false, IsNoButton = true };
            BaseHeightControl.Floor floor_3 = new BaseHeightControl.Floor() { FloorNumber = 3, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false, IsNoButton = true };
            BaseHeightControl.Floor floor_4 = new BaseHeightControl.Floor() { FloorNumber = 4, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_5 = new BaseHeightControl.Floor() { FloorNumber = 5, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_6 = new BaseHeightControl.Floor() { FloorNumber = 6, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_7 = new BaseHeightControl.Floor() { FloorNumber = 7, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_8 = new BaseHeightControl.Floor() { FloorNumber = 8, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_9 = new BaseHeightControl.Floor() { FloorNumber = 9, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_10 = new BaseHeightControl.Floor() { FloorNumber = 10, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_11 = new BaseHeightControl.Floor() { FloorNumber = 11, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_12 = new BaseHeightControl.Floor() { FloorNumber = 12, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_13 = new BaseHeightControl.Floor() { FloorNumber = 13, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_14 = new BaseHeightControl.Floor() { FloorNumber = 14, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_15 = new BaseHeightControl.Floor() { FloorNumber = 15, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_16 = new BaseHeightControl.Floor() { FloorNumber = 16, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_17 = new BaseHeightControl.Floor() { FloorNumber = 17, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_18 = new BaseHeightControl.Floor() { FloorNumber = 18, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_19 = new BaseHeightControl.Floor() { FloorNumber = 19, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_20 = new BaseHeightControl.Floor() { FloorNumber = 20, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_21 = new BaseHeightControl.Floor() { FloorNumber = 21, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_22 = new BaseHeightControl.Floor() { FloorNumber = 22, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_23 = new BaseHeightControl.Floor() { FloorNumber = 23, Height = 3.5d, IsUpButtonOn = false, IsDownButtonOn = false };
            BaseHeightControl.Floor floor_24 = new BaseHeightControl.Floor() { FloorNumber = 24, Height = 4.0d, IsUpButtonOn = false, IsDownButtonOn = false,IsTopOrBottom= FloorLevel.Top };

            OneBuilding.Floors.Add(floor_B1);
            OneBuilding.Floors.Add(floor_1);
            OneBuilding.Floors.Add(floor_2);
            OneBuilding.Floors.Add(floor_3);
            OneBuilding.Floors.Add(floor_4);
            OneBuilding.Floors.Add(floor_5);
            OneBuilding.Floors.Add(floor_6);
            OneBuilding.Floors.Add(floor_7);
            OneBuilding.Floors.Add(floor_8);
            OneBuilding.Floors.Add(floor_9);
            OneBuilding.Floors.Add(floor_10);
            OneBuilding.Floors.Add(floor_11);
            OneBuilding.Floors.Add(floor_12);
            OneBuilding.Floors.Add(floor_13);
            OneBuilding.Floors.Add(floor_14);
            OneBuilding.Floors.Add(floor_15);
            OneBuilding.Floors.Add(floor_16);
            OneBuilding.Floors.Add(floor_17);
            OneBuilding.Floors.Add(floor_18);
            OneBuilding.Floors.Add(floor_19);
            OneBuilding.Floors.Add(floor_20);
            OneBuilding.Floors.Add(floor_21);
            OneBuilding.Floors.Add(floor_22);
            OneBuilding.Floors.Add(floor_23);
            OneBuilding.Floors.Add(floor_24);

            

            OneBuilding.Floors= OneBuilding.Floors.OrderByDescending(x => x.FloorNumber).ToList();
            OneBuilding.Altitude();//获取楼层高度，楼层数据做好后，要计算一下。

            #endregion


        }

        private void OneBuilding_ReBackData_InBuilding(string Msg)
        {
            ReBackData_InTake?.Invoke(Msg);
        }
    }
}
